<template>
  <div class="yy">
    <div class="box">
      <span>筛选查询</span>
      <span class="s2" @click="cha">查询结果</span>
    </div>
    <div class="box2">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="项目编号">
          <el-input
            v-model="formInline.user"
            placeholder="输入项目编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="项目状态">
          <el-select v-model="formInline.region">
            <el-option label="进行中" value="进行中"></el-option>
            <el-option label="已完成" value="已完成"></el-option>
            <el-option label="已延期" value="已延期"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="box">
      <span>数据列表</span>
      <span class="s2" @click="dialogFormVisible = true">新增</span>
    </div>

    <div class="box3">
      <tabales :tableData="listarr" @dlelistid="dlelistid" />
      <pag @handleCurrentChange="handleCurrentChange"/>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose"
      >
        <span>确定要删除内容吗</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dle">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 添加插件 -->
      <el-dialog title="欢迎来到" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="项目编号">
              <el-input v-model="form.number"></el-input>
            </el-form-item>
            <el-form-item label="项目名称">
              <el-input v-model="form.itemName"></el-input>
            </el-form-item>
            <el-form-item label="项目负责人">
              <el-input v-model="form.username"></el-input>
            </el-form-item>

            <el-form-item label="当前阶段">
              <el-select v-model="form.current" placeholder="请选择当前阶段">
                <el-option label="需求对接" value="需求对接"></el-option>
                <el-option label="不需求对接" value="不需求对接"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目状态">
              <el-select v-model="form.state" placeholder="请选择项目状态">
                <el-option label="已完成" value="已完成"></el-option>
                <el-option label="已延期" value="已延期"></el-option>
                <el-option label="进行中" value="进行中"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="活动时间">
              <el-col :span="11">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="form.start"
                  style="width: 100%"
                ></el-date-picker>
              </el-col>
              <el-col class="line" :span="2">-</el-col>
              <el-col :span="11">
                <el-time-picker
                  placeholder="选择时间"
                  v-model="form.dateb"
                  style="width: 100%"
                ></el-time-picker>
              </el-col>
            </el-form-item>
          </el-form>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="add">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import dlalag from "./dialag";
import tabales from "./tabales";
import pag from "./pag";
import { getlistApi } from "../../../api/userApi";
export default {
  components: { tabales, pag, dlalag },
  data() {
    return {
      form: {
        id: "1",
        number: "",
        // datea: "",
        dateb: "",
        start: "",
        itemName: "",
        username: "",
        current: "",
        state: "",
      },
      dialogTableVisible: false,
      dialogFormVisible: false,
      formLabelWidth: "120px",
      //查询项目编号的数据
      formInline: {
        user: "",
        region: "",
      },
      listarr: [],
      listarr2:[],
      dialogVisible: false,
      id: "",
    };
  },
  async mounted() {
    let res = await getlistApi();
    console.log(res.data.userlist);
    this.listarr = res.data.userlist;
    this.listarr2 = res.data.userlist;
    console.log();
  },
  methods: {
    //接受分页穿的数据
    handleCurrentChange(data){
      this.listarr=data
    },
    //查找
    cha() {
      this.listarr=this.listarr2
      if (this.formInline.user != "") { 
        let res = this.listarr.filter((item) => item.number == this.formInline.user);
        this.listarr=res
      }else{
        this.listarr=this.listarr2
       
      }
      

      // console.log(this.formInline.user);
    },
    //添加按钮
    add() {
      this.dialogFormVisible = false;

      this.listarr.unshift(this.form);
      this.form = {};
    },

    // 删除按钮
    dlelistid(id) {
      this.id = id;
      // console.log(this.id);
      this.dialogVisible = true;
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    dle() {
      this.listarr = this.listarr.filter((item) => item.id !== this.id);
      this.dialogVisible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.yy {
  overflow: hidden;

  .box3 {
    .el-input__inner {
      width: 245px;
    }
    width: 1300px;
    // height: 100vh;
    margin: 0px 30px 0px;
    // background-color: #63b9be;
  }
  .box {
    width: 1300px;
    height: 51px;
    background-color: rgba(242, 242, 242);
    margin: 80px 30px 0px;
    display: flex;
    justify-content: space-around;
    text-align: center;
    align-items: center;
    font-size: 12px;
    color: #666666;
    .s2 {
      width: 73px;
      height: 36px;
      background-color: rgba(255, 255, 255);
      color: #63b9be;
      line-height: 36px;
      cursor: pointer;
    }
  }
  .box2 {
    padding-top: 12px;
    margin-bottom: 30px;
    height: 56px;
    margin-left: 30px;
    border: 1px solid rgba(242, 242, 242);
    ::v-deep {
      .el-form-item__label {
        margin-left: 50px;
        font-size: 12px;
        color: #666666;
      }
      .el-input__inner {
        height: 40px;
        width: 140px;
      }
    }
  }
}
</style>